/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.faytechcc.csc251.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 *
 * @author Kent
 */
public class BuildCollectionTable {
    public static void main(String[] args) 
            throws Exception
    {
        final String DB_URL = 
                "jdbc:derby:MTGCardDB";
        
        try
        {
            //Create a connection to the database.
            Connection conn = DriverManager.getConnection(DB_URL);
            
            //Create a Statement object
            Statement stmt = conn.createStatement();
            
            //Create the card table
            System.out.println("Creating the Collection table...");
            String sql = "CREATE TABLE Collection" +
                    "( Name CHAR(50), " +
                    "SetName CHAR(50), " +
                    "ID CHAR(10) NOT NULL REFERENCES Card(ID), " +
                    "Type CHAR(50), " +
                    "Power CHAR(5), " +
                    "Toughness CHAR(5), " +
                    "Manacost CHAR(50), " +
                    "ConvertedManacost CHAR(10), " +
                    "Color CHAR(10), " +
                    "Rarity CHAR(10), " +
                    "Ability CLOB(700), " +
                    "CollectionNum INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1))";
            stmt.execute(sql);
            
            //Close the resources
            stmt.close();
            conn.close();
            System.out.println("Done");
        }
        catch(Exception ex)
        {
            System.out.println("ERROR: " + ex.getMessage());
        }
    }
}
